package com.yutian.springbootfreemarker.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/hello")
public class HelloController {


	@GetMapping("")
    public String hello(Model model, HttpServletRequest httpRequest){
	    // 返回字符串，框架默认会去加载 classpath:/templates/ 目录下的页面
        model.addAttribute("name", "雨田");
        model.addAttribute("job", "JAVA老师");
        return "index";
    }

    @GetMapping("/{name}")
    @ResponseBody
    public String hello(@PathVariable("name") String name, HttpServletRequest httpRequest){
        // @ResponseBody 则直接返回字符串
        return "hello, " + name;
    }
}
